﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CourseShare.aspx.cs" Inherits="ZX.WebApp.TR.CourseShare" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <!--CSS file (default YUI Sam Skin) -->
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/reset-fonts-grids/reset-fonts-grids.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/menu/assets/skins/sam/menu.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link type="text/css" rel="stylesheet" href="../Scripts/yui_2.9.0/build/datatable/assets/skins/sam/datatable.css" />
    <!--begin custom header content for this example-->
    <style type="text/css">
        body
        {
             background-color:#eeeeee;    
        }
    .yui-skin-sam table {
	    width: 100%;
    }
    
    #button-example-form fieldset, 
    #button-example-form fieldset div {

        border: 2px groove #ccc;
        margin: .5em;
        padding: .5em;

    }

    .yui-button#pushbutton2 button,
    .yui-button#pushbutton5 button, 
    .yui-button .Add button {
        background: url(../button/assets/add.gif) center center no-repeat;
        text-indent: -4em;
        overflow: hidden;
        padding: 0 .75em;
        width: 2em;
        *margin-left: 4em;   /* IE only */
        *padding: 0 1.75em;  /* IE only */

    }
    
    .yui-button#pushbutton3 button,
    .yui-button#pushbutton6 button, 
    .yui-button#pushbutton9 button {

        padding-left: 2em;
        background: url(../button/assets/add.gif) 10% 50% no-repeat;
    
    }
    <% =DataTableCss %>
    </style>
    <!--end custom header content for this example-->
    <!-- Dependencies -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <!-- OPTIONAL: JSON Utility (for DataSource) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <!-- OPTIONAL: Connection Manager (enables XHR for DataSource) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <!-- OPTIONAL: Get Utility (enables dynamic script nodes for DataSource) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <!-- OPTIONAL: Drag Drop (enables resizeable or reorderable columns) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/dragdrop/dragdrop-min.js"></script>
    <!-- OPTIONAL: Calendar (enables calendar editors) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/calendar/calendar-min.js"></script>
    <!-- Source files -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/datatable/datatable-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/resize/resize-min.js"></script>
</head>
<body class="yui-skin-sam">
    <form id="form1" runat="server" >
    <!-- 工具栏 -->
    <div id="listpage">
        <div id="toolbar" style="margin: 2px; ">
            <button type="button" id="btnAddNew" name="btnAddNew">
                新增</button>
             <button type="button" id="btnEdits" name="btnEdits">
                编辑</button>
             <button type="button" id="btnDelete" name="btnDelete">
                删除</button>
            <button type="button" id="btnEdit" name="btnEdit">
                点评</button>
            <button type="button" id="btnQuery" name="btnQuery">
                查找</button>
            <button type="button" id="btnLook" name="btnLook">
                查看</button>
        </div>
        <div id="data">
            <div id="json">
            </div>
        </div>
        <div id="bottom">
        </div>
    </div>
    <div id="dialog1" class="yui-pe-content">
        <div class="hd">
            心得点评管理</div>
        <div class="bd">
            <iframe id="EditUIWindow" frameborder="0" src="" style="width: 100%; height: 100%;
                margin: 0px; padding: 0px;"></iframe>
        </div>
    </div>
    <div id="dialog3" class="yui-pe-content">
        <div class="hd">
            提示</div>
        <div class="bd">
            你正在删除当前选择的数据，继续请按确定？
        </div>
    </div>
    </form>
</body>
<script type="text/javascript">
     var const_entityID = "<% =EntityId %>",    //实体ID名称
        const_entityName = "<% =EntityName %>",//实体名称
        const_EditEntity = "<% =EditEntity %>",//编辑实体名
        const_functionId   ="<% =FunctionID %>" ,
        selectControl=null;
    (function () {
        var Dom = YAHOO.util.Dom,
        Event = YAHOO.util.Event;

        Event.onDOMReady(function () {
            var layout = new YAHOO.widget.Layout({
                units: [
                { position: 'top',height: 35, body: 'toolbar', gutter: '1 1 1 1', scroll: null, zIndex: 2 },
                {position: 'center', body: 'data', gutter: '1 1', scroll: true },
                { position: 'bottom', height: 30, body: 'bottom', gutter: '1 1'}
            ]
            });
            layout.render();
        });
    })();

 
    //新增
    var TrActivityCourseID;
    var type;
    var fnAdd = function(){         
        TrActivityCourseID="0000-0000-0000-0000";
        type=1;
        document.getElementById("EditUIWindow").src="EditCourseActivity.aspx?ID="+TrActivityCourseID+"&type="+type+"&entity=<%=EntityName%>";
        YAHOO.example.container.dialog1.show();
    }   
    //点评
    var fnEdit = function(key){
        var oRecord;                  
        var selectRows = myDataTable.getSelectedRows();                     
        if(selectRows.length!=null && selectRows.length==1){                
            oRecord = myDataTable.getRecordSet().getRecord(selectRows[0]);                           
            TrActivityCourseID=YAHOO.lang.dump(oRecord.getData("TrGainShareID"));
            type=3;
            document.getElementById("EditUIWindow").src="EditCourseActivity.aspx?ID="+TrActivityCourseID+"&type="+type+"&entity=<%=EntityName%>";
            YAHOO.example.container.dialog1.show();
        }
        else{
            alert("请选中一行活动记录做点评管理");
        }             
    }
    //编辑
    var fnEdits = function(){
        var oRecord;                  
        var selectRows = myDataTable.getSelectedRows();                     
        if(selectRows.length!=null && selectRows.length==1){                  
            oRecord = myDataTable.getRecordSet().getRecord(selectRows[0]);                           
            TrActivityCourseID=YAHOO.lang.dump(oRecord.getData("TrGainShareID"));
            type=2;
            document.getElementById("EditUIWindow").src="EditCourseActivity.aspx?ID="+TrActivityCourseID+"&type="+type+"&entity=<%=EntityName%>";
            YAHOO.example.container.dialog1.show();
        }
        else{
            alert("请选中一行活动记录做心得管理");
        }             
    }
    //查看
    var fnLook = function(){
        var oRecord;                  
        var selectRows = myDataTable.getSelectedRows();                     
        if(selectRows.length!=null && selectRows.length==1){                  
            oRecord = myDataTable.getRecordSet().getRecord(selectRows[0]);                           
            TrActivityCourseID=YAHOO.lang.dump(oRecord.getData("TrGainShareID"));
            type=4;
            document.getElementById("EditUIWindow").src="EditCourseActivity.aspx?ID="+TrActivityCourseID+"&type="+type+"&entity=<%=EntityName%>";
            YAHOO.example.container.dialog1.show();
        }
        else{
            alert("请选中一行活动记录做心得管理");
        }
    }
    //删除
    var SaveUrl;
    var fnDelete = function(){
        var oRecord;                  
        var selectRows = myDataTable.getSelectedRows();                     
        if(selectRows.length!=null && selectRows.length==1){                  
            oRecord = myDataTable.getRecordSet().getRecord(selectRows[0]);                           
            TrActivityCourseID=YAHOO.lang.dump(oRecord.getData("TrGainShareID"));
            type=5;
            SaveUrl="CourceShareList.aspx?ID="+TrActivityCourseID+"&type="+type+"";
            YAHOO.example.container.dialog3.show();
        }
        else{
            alert("请选中一行记录!");
        }             
    }
    //删除
    function DeleteData()
    {
        YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
            success: function (res) {
                try {
                    var str = res.responseText;
                    if(str=="1"){
                        YAHOO.example.container.dialog3.hide();
                        alert("数据删除成功");
                        LoadData();
                    }
                    else
                    {
                        alert(str+"\n"+"数据删除失败!");
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
    }
    //查询
    var fnQuery = function(){
    }
    //导出
    var fnExport = function(){
    }
    //报表
    var fnReport = function(){
    }

    YAHOO.example.init = function () {
        // "click" event handler for each Button instance
        function onButtonClick(p_oEvent) {
                 YAHOO.log("You clicked button: " + this.get("id"), "info", "example1");
                 switch(this.get("id"))
                 { 
                    case "btnAddNew":
                         fnAdd();
                         break;
                    case "btnEdit":
                         fnEdit();
                          break;
                    case "btnEdits":
                         fnEdits();
                          break;
                    case "btnDelete":
                         fnDelete();
                          break;
                    case "btnQuery":
                         fnQuery();
                         break;
                    case "btnExport":
                         fnExport();
                         break;
                    case "btnReport":
                         fnReport();
                         break;
                    case "btnLook":
                         fnLook();
                         break;
                    default:
                         fnAdd();
                         break;
                 }                        
        }

        // "contentready" event handler for the "pushbuttonsfrommarkup" <fieldset>

        YAHOO.util.Event.onContentReady("toolbar", function () {
            // Create Buttons using existing <input> elements as a data source
            var btnAddNew = new YAHOO.widget.Button("btnAddNew");
            var btnEdit = new YAHOO.widget.Button("btnEdit");
            var btnQuery = new YAHOO.widget.Button("btnQuery");
            var btnEdits = new YAHOO.widget.Button("btnEdits");
            var btnDelete = new YAHOO.widget.Button("btnDelete");
            var btnLook = new YAHOO.widget.Button("btnLook");
            btnAddNew.on("click", onButtonClick);
            btnEdits.on("click", onButtonClick);
            btnQuery.on("click", onButtonClick);
            btnEdit.on("click", onButtonClick);
            btnDelete.on("click", onButtonClick);
            btnLook.on("click", onButtonClick);
        });
    }();

    function AddButton() {
        var button = document.createElement('button');
        button.innerHTML = 'add tab';
        YAHOO.util.Event.on(button, 'click', addTab);
        tabView.appendChild(button);
    }


    //DataTable 
    var mDataTable;
    //刷新数据
    function LoadData()
    {
       BindData();
    }

    //关闭窗口
    function closeWin(){
        LoadData();
        YAHOO.example.container.dialog1.hide();
    }
    //数据绑定
    function BindData() {
        YAHOO.example.XHR_JSON = function() {
            var formatUrl = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = "<a href='" + oRecord.getData("ClickUrl") + "' target='_blank'>" + sData + "</a>";
            };
        
            var formatRating = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = (sData === null) ? "N/A" : YAHOO.util.Number.format(sData);
            };

            var myColumnDefs = [
                 <% = DataFields %>
            ];

            var myDataSource = new YAHOO.util.DataSource("../Extend/AjaxData/JSONList.aspx?");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
            myDataSource.connXhrMode = "queueRequests";
            myDataSource.responseSchema = {
                resultsList: "rows",
                //fields: ["EntityName", "THCaption", "Field", { key: "Rating.AverageRating", parser: "number" }, "Width"]
                fields: [<% = DataColums %>]
            };
        
            this.myDataTable = new YAHOO.widget.DataTable("json", myColumnDefs,
                    myDataSource, {initialRequest: "entity=<%=EntityName%>&order=<% =Order %>&r="+Math.random()+"&zip=94089&results=10&output=json&functionid="+const_functionId,selectionMode:"single"  });
            mDataTable =this.myDataTable;        
            var mySuccessHandler = function() {
                this.set("sortedBy", null);
                this.onDataReturnAppendRows.apply(this,arguments);
            };
            var myFailureHandler = function() {
                this.showTableMessage(YAHOO.widget.DataTable.MSG_ERROR, YAHOO.widget.DataTable.CLASS_ERROR);
                this.onDataReturnAppendRows.apply(this,arguments);
            };
            var callbackObj = {
                success : mySuccessHandler,
                failure : myFailureHandler,
                scope : myDataTable
            };
        
    
	        // Subscribe to events for row selection 
	        this.myDataTable.subscribe("rowMouseoverEvent", this.myDataTable.onEventHighlightRow); 
	        this.myDataTable.subscribe("rowMouseoutEvent", this.myDataTable.onEventUnhighlightRow); 
            this.myDataTable.subscribe("rowClickEvent", this.myDataTable.onEventSelectRow); 
 
            // Programmatically select the first row 
            this.myDataTable.selectRow(this.myDataTable.getTrEl(0)); 
            hideCol();
        }();
    }
    //隐藏/栏位
    function hideCol(){ mDataTable.hideColumn(parseInt(0)); mDataTable.refreshView(); }; 
    YAHOO.util.Event.addListener(window, "load", BindData);

   YAHOO.namespace("example.container");

    YAHOO.util.Event.onDOMReady(function () {

        // Define various event handlers for Dialog
        var handleSubmit = function () {
            var editwindow = document.getElementById("EditUIWindow");
            if (editwindow)
             {
                editwindow.contentWindow.Save();
            }
        };

        var handleCancel = function () {
            this.cancel();
        };
        var handleSuccess = function (o) {
            var response = o.responseText;
            response = response.split("<!")[0];
            document.getElementById("resp").innerHTML = response;
        };
        var handleFailure = function (o) {
            alert("Submission failed: " + o.status);
        };

        // Remove progressively enhanced content class, just before creating the module
        YAHOO.util.Dom.removeClass("dialog1", "yui-pe-content");

        // Instantiate the Dialog
        YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1",
							{ width: "620",
							    height: "610px",
							    fixedcenter: true,
							    visible: false,
							    constraintoviewport: true,
							    buttons: [{ text: "保存", handler: handleSubmit, isDefault: true },
								      { text: "取消", handler: handleCancel}]
							});
        YAHOO.example.container.dialog3= new YAHOO.widget.Dialog("dialog3", 
							    { width : "350px",
							      height: "90px",
                                  fixedcenter: true,
                                  visible: false,
                                  draggable: true,
                                  close: true,
                                  autofillheight: "body", 
							      constraintoviewport : true,
							      buttons : [ { text:"确定", handler:DeleteData, isDefault:true },
								          { text:"取消", handler:handleCancel } ]
							    });
        // Validate the entries in the form to require that both first and last name are entered
        YAHOO.example.container.dialog1.validate = function () {
            var data = this.getData();
            if (data.firstname == "" || data.lastname == "") {
                alert("Please enter your first and last names.");
                return false;
            } else {
                return true;
            }
        };

        // Wire up the success and failure handlers
        YAHOO.example.container.dialog1.callback = { success: handleSuccess,
            failure: handleFailure
        };

        // Render the Dialog
        YAHOO.example.container.dialog1.render();
        YAHOO.example.container.dialog3.render();
        YAHOO.util.Event.addListener("btnAddNew", "click", YAHOO.example.container.dialog1.show, YAHOO.example.container.dialog1, true);
    });
</script>
</html>
